package ru.vsu.cs.pm.models;

import org.apache.wicket.injection.web.InjectorHolder;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import ru.vsu.cs.pm.beans.AccountManager;
import ru.vsu.cs.pm.beans.ItemManager;

/**
 * User: Oleg
 * Date: 28.12.2010
 * Time: 15:08:00
 */
public class ItemModel extends LoadableDetachableModel<Item> {

    @SpringBean
    private ItemManager itemManager;

    private Integer id;

    public ItemModel() {
        InjectorHolder.getInjector().inject(this);
    }

    public ItemModel(Integer id) {
        this.id = id;
        InjectorHolder.getInjector().inject(this);
    }

    public ItemModel(Item item) {
        super(item);
        this.id = item.getId();
        InjectorHolder.getInjector().inject(this);
    }

    @Override
    protected Item load() {
        if(id == null) {
            return new Item();
        }
        return itemManager.getItem(id);
    }
}